package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.sch.rfview.AnimRFRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.login.view.LoginActivity;
import xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.presenter.IndexTopPresenter;

/**
 * Created by lenovo on 2016/10/18.
 */

public class BeautyShopFragment extends Fragment {
    @BindView(R.id.beautyshop_progressbar)
    ProgressBar beautyshopProgressbar;
    @BindView(R.id.recyclerView_beauty)
    AnimRFRecyclerView recyclerViewBeauty;
//    @BindView(R.id.ptrFramelayout_recycler_beauty)
//    PtrFrameLayout ptrFramelayoutRecyclerBeauty;
    private Context context;
    @BindView(R.id.navicon_beauty)
    ImageView naviconBeauty;
    @BindView(R.id.edit_beauty)
    EditText editBeauty;
    @BindView(R.id.message_beauty)
    ImageView messageBeauty;
    @BindView(R.id.toolbar_beautyshop)
    LinearLayout toolbarBeautyshop;

    private Unbinder bind;
    private IndexTopPresenter presenter;
    int curPager =1;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_beauty_layout, container, false);
        bind = ButterKnife.bind(this, view);

        //创建presenter对象 调用presenter中的初始化recyclerview的方法
        presenter = new IndexTopPresenter(recyclerViewBeauty, context, getActivity().getLayoutInflater());
        presenter.initRecyclerView();
        //继续向下加载数据
       presenter.reload();

        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @OnClick({R.id.navicon_beauty, R.id.edit_beauty, R.id.message_beauty})
    public void onClick(View view) {
        switch (view.getId()) {
            //开启所有类别的Activity
            case R.id.navicon_beauty:
                satrtNewActivity(CategoryActivity.class);
                break;
            //跳转到搜索界面
            case R.id.edit_beauty:

                break;
            //跳转到消息界面 需要判断登录
            case R.id.message_beauty:
                satrtNewActivity(LoginActivity.class);
                break;
        }
    }

    /**
     *
     */
    public void satrtNewActivity(Class<? extends Activity> clazz) {
        Intent intent = new Intent(context, clazz);
        startActivity(intent);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
